<?php

class ManufacturerController extends Controller
{
	public function actionIndex(){

		echo CHtml::tag('title',array(),'Производители'.' | '.CHtml::encode(Yii::app()->name))."\n";
		Yii::app()->clientScript->registerMetaTag('', 'description');
		Yii::app()->clientScript->registerMetaTag('', 'keywords');

		$this->breadcrumbs=array(
			'Производители',
		);
		
		$criteria = new CDbCriteria();
		
		$criteria->order = 'title ASC';
		
		$count=Manufacturer::model()->count($criteria);
		$pages=new CPagination($count);
		$pages->pageSize='20';
		$pages->applyLimit($criteria);
		$manufacturers = Manufacturer::model()->findAll($criteria);

		$this->yiistoRender('index', array(
			'manufacturers' => $manufacturers,
			'count' => $count,
			'pages' => $pages,
		));
	}

	public function actionSingle($id=''){

		$meta = Manufacturer::model()->findbypk($id);

		echo CHtml::tag('title',array(), Manufacturer::model()->title($meta['id']).CHtml::encode(Yii::app()->name))."\n";
		Yii::app()->clientScript->registerMetaTag(Manufacturer::model()->keywords($meta['id']), 'keywords');
		Yii::app()->clientScript->registerMetaTag(Manufacturer::model()->description($meta['id']), 'description');

		$this->breadcrumbs=array(
			'Производители'=>array('manufacturer/index'),
			$meta['title'],
		);

		//товары этого производителя
		$items = $meta->items;
		
		$category = array();
		foreach($items as $item){
			$category[] = $item->category;
		}
		$category = array_unique($category);

		$this->yiistoRender('single',array(
			'meta' => $meta,
			'items' => $items,
			'category' => $category,
		));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}